<?php
declare (strict_types = 1);

namespace app\middleware;

use app\BaseController;
use app\Request;
use Closure;
use isszz\sensitive\facade\Sensitive;
use think\response\Json;

class Login
{
    /**
     * 处理请求
     * @param Request $request
     * @param Closure $next
     * @return mixed|Json
     */
    public function handle(Request $request, Closure $next)
    {
	    
	    if (!empty($request->get())||!empty($request->post())){
		    $data = $request->get() + $request->post();
		    $params = json_encode($data,JSON_UNESCAPED_UNICODE);
		    // 检测敏感词
		    $words = Sensitive::get(content: $params);
		    if (!empty($words)) {
			    writeJson(0,'内容包含敏感信息:'.json_encode($words,JSON_UNESCAPED_UNICODE));
		    }
	    }
        if ($request->users_id==0){
           writeJson(100,'重新登陆');
        }
        return $next($request);
    }
}
